home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
DB_CLIPP
/
0411.ZIP
/
STRIPP.C
< prev
next >
Wrap
Text File
|
1985-05-28
|
3KB
|
139 lines
/*
* Program to read a file and strip nominated characters from it.
*/
#include "stdio.h"
main(argc,argv)
int argc;
char *argv[];
{
int c,
outfile,
infile,
cntr,
oneflag;
long value;
if (argc == 1)
{
puts("\n");
puts("Syntax: STRIPP <infile> <outfile> /nn [/1]\n\n");
puts("where infile is the filespec for the input data\n");
puts(" outfile is the filespec for the output data\n\n");
puts(" /nn is the hex value of the character to\n");
puts(" be stripped from the file\n");
puts(" /1 indicates that only the 1st character\n");
puts(" which meets the specifications should\n");
puts(" be deleted.\n\n");
exit(0);
}
if (argc == 1)
{
puts("Author: Peter Townsend\n");
puts("Date: 28May85\n");
puts("Version: 1.0\n");
}
if ((infile = open(argv[1],0)) == -1)
{
printf("\nCannot open input file %s\n",argv[1]);
exit(1);
}
if (argc == 2)
{
printf("\nMissing Output Filename\n");
exit(1);
}
if (strcmp(argv[1],argv[2]) == 0)
{
printf("\nInput filename and output filename cannot be the same.\n");
exit(1);
}
if ((outfile = open(argv[2],1)) == -1)
{
if ((outfile = creat(argv[2])) == -1)
{
printf("\nCannot open/create output file %s\n",argv[2]);
exit(1);
}
}
if (argc == 3)
{
printf("\nMissing hex character value\n");
exit(1);
}
if ((argv[3][0]) == '/')
{
value = 0;
c = tolower(argv[3][1]);
if ((c >= '0') && (c <= '9'))
{
value = (c - '0') * 16;
}
else
{
if ((c < 'a') || (c > 'f'))
{
printf("\nInvalid hex number %s\n",argv[3]);
exit(1);
}
else
{
value = (c - 'a' + 10) * 16;
}
}
c = tolower(argv[3][2]);
if ((c >= '0') && (c <= '9'))
{
value = value + (c - '0');
}
else
{
if ((c < 'a') || (c > 'f'))
{
printf("\nInvalid hex number %s\n",argv[3]);
exit(1);
}
else
{
value = value + (c - 'a' + 10);
}
}
}
else
{
puts("\nYou have not specified a (hex) character");
puts("\nto be stripped from your file.\n\n");
exit(1);
}
if (argc > 4)
{
if (strcmp(argv[4],"/1") == 0)
{
oneflag = 1;
}
else
{
oneflag = 0;
}
}
else
{
oneflag = 0;
}
while ((c = fgetc(infile)) != EOF)
{
if (c != value)
{
putc(c,outfile);
}
else
{
if (oneflag == 1)
{
value = 256 + value;
}
}
}
fclose(infile);
fclose(outfile);
exit(0);
}